package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.User;
import com.kaishengit.util.db.DBHelp;
import com.kaishengit.util.db.RowMapper;

public class UserDao {

	private DBHelp<User> db = new DBHelp<User>();
	
	public User findByName(String name) {
		String sql = "select id,name,password,pic from t_user where name = ?";
		return db.executeQueryToObject(sql, new UserRowMapper(), name);
	}
	
	public List<User> findAll() {
		String sql = "select id,name,password,pic from t_user";
		return db.executeQueryToList(sql,new UserRowMapper());
	}
	public class UserRowMapper implements RowMapper<User>{

		public User mapRow(ResultSet rs) throws SQLException {
			User u = new User();
			u.setId(rs.getString("id"));
			u.setName(rs.getString("name"));
			u.setPassword(rs.getString("password"));
			u.setPic(rs.getString("pic"));
			return u;
		}
		
	}
}
